package com.higold.cloud.mvp.presenter

import com.higold.cloud.base.BasePresenter
import com.higold.cloud.mvp.contract.ShopDetailContract
import com.higold.cloud.mvp.model.ShopDetailModel
import com.higold.cloud.net.exception.ExceptionHandle

/**
 *    author : lxz
 *    date   : 2019/10/12 14:57
 *    desc   :
 */

class ShopDetailPresenter : BasePresenter<ShopDetailContract.View>(), ShopDetailContract.Presenter {

    private val shopDetailModel by lazy { ShopDetailModel() }

    override fun getShopDetail(shopId : Int) {
        checkViewAttached()
        mRootView?.showLoading()
        val disposable = shopDetailModel.getShopDetail(shopId)
                .subscribe({ shopDetail ->
                    mRootView?.setShopDetail(shopDetail)
                }, { throwable ->
                    //处理异常
                    mRootView?.showError(ExceptionHandle.handleException(throwable), ExceptionHandle.errorCode)
                })
        addSubscription(disposable)
    }
}